package com.icesoft.system.service.impl;

import com.icesoft.framework.core.service.impl.BaseServiceImpl;
import com.icesoft.system.entity.Permission;
import com.icesoft.system.entity.UserRole;
import com.icesoft.system.mapper.PermissionMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class PermissionServiceImpl extends BaseServiceImpl<PermissionMapper, Permission> {

	private final UserRoleServiceImpl userRoleService;

	public List<Permission> getPermission(Serializable id) {
		List<Long> roleIds = new ArrayList<>();
		for (UserRole userRole : userRoleService.lambdaQuery().eq(UserRole::getUserId, id).list()) {
			roleIds.add(userRole.getRoleId());
		}
		return lambdaQuery().in(Permission::getRoleId, roleIds).list();
	}
}
